
/**
 * leftNavBar vuex
 */
// import posts from '@/plugins/request'
import storage from '@/plugins/localStorage'


const state = {
  pageTree: {},
  activeIndex: '1-1'
}

const getters = {
  //获取左侧菜单栏 path 信息
  getPageTree: state => {
    if(state.pageTree.length) {
      return state.pageTree
    }else if(storage.get('userInfo')) {
      return JSON.parse(storage.get('userInfo')).trees.children
    }else {
      return []
    }
  },
  getActiveIndex: state => state.activeIndex
}

const actions = {}

const mutations = {
  updatePageTree(state, data) {
    state.pageTree = data
  },
  changeActiveIndex(state, index) {
    state.activeIndex = index
  }
}
export default {
  state,
  getters,
  actions,
  mutations
}
